import _mysql

def createDb(name, username, password):
    db = _mysql.connect("localhost", "root", "AU6xA2Ns", "mysql")
    try:
        db.query("CREATE DATABASE "+name)
    except:
        return
    
    if password:
        p = "IDENTIFIED BY '%s'"%password
    else:
        p = ""
    db.query("GRANT ALTER, CREATE, DELETE, DROP, INDEX, INSERT, LOCK TABLES, SELECT, UPDATE ON %s.* TO '%s'@'localhost' %s"%(name, username, p))
    db.close()
    
def changePassword(name, password):
    db = _mysql.connect("localhost", "root", "AU6xA2Ns", "mysql")
    db.query("SELECT * FROM `user` WHERE `User` = '%s'"%name)
    if db.store_result().fetch_row():
        db.query("SET PASSWORD FOR '%s'@'localhost' = PASSWORD('%s')"%(name, password))
    db.close()
